import random
from selenium.webdriver.common.by import By
from tool.database_process import DatabaseProcess
from tool.get_log import GetLogging

logger = GetLogging().get_logging()

order_id = None
user_cart_id = None
"""首页URL"""
url = "http://tast.shop.com"
back_url = "http://tast.shop.com/adminjytdwt.php?s=admin/logininfo.html"

"""登录相关的元素"""
# 登录链接
login_link = By.XPATH, "/html/body/div[1]/div[1]/div[2]/div/ul[1]/div/div/a[1]"
# 用户名
login_username = By.NAME, "accounts"
# 密码
login_password = By.NAME, "pwd"
# 验证码
login_verify = By.NAME, "verify"
# 验证码图片
login_verify_img = By.ID, "form-verify-img"
# 更换验证码链接
login_update_verify = By.XPATH, "/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/span[1]/span/a"
# 登录按钮
login_btn = By.CSS_SELECTOR, "button[type='submit']"
# 异常信息文本
login_error_text = By.CLASS_NAME, "prompt-msg"
# 退出链接
login_logout_link = By.LINK_TEXT, "[退出]"

"""注册相关的元素"""
# 注册链接
register_link = By.LINK_TEXT, "注册"
# 用户名
register_username = By.NAME, "accounts"
# 密码
register_pwd = By.NAME, "pwd"
# 验证码
register_verify = By.NAME, "verify"
# 验证码图片
register_verify_img = By.ID, "form-verify-img"
# 更换验证码链接
register_update_verify = By.XPATH, "/html/body/div[1]/div[1]/div[3]/div/div/div[2]/div/div[1]/div[1]/form/div[3]/span[1]/span/a"
# 勾选协议框
register_check_agree = By.XPATH, "/html/body/div[1]/div[1]/div[3]/div/div/div[2]/div/div[1]/div[1]/form/div[4]/label/span"
# 注册按钮
register_btn = By.CSS_SELECTOR, "button[type='submit']"
# 异常信息文本
register_error_text = By.CLASS_NAME, "prompt-msg"
# 退出链接
register_logout_link = By.LINK_TEXT, "[退出]"

"""商品购买流程中登录相关的元素"""
# 登录链接
product_login_link = By.XPATH, "/html/body/div[1]/div[1]/div[2]/div/ul[1]/div/div/a[1]"
# 用户名
product_login_username = By.NAME, "accounts"
# 密码
product_login_password = By.NAME, "pwd"
# 验证码
product_login_verify = By.NAME, "verify"
# 验证码图片
product_login_verify_img = By.ID, "form-verify-img"
# 登录按钮
product_login_btn = By.CSS_SELECTOR, "button[type='submit']"
# 提示信息
product_hint_info = By.CLASS_NAME, "prompt-msg"

"""商品搜索与选择相关的元素"""
# 商品搜索输入框
product_search_input = By.ID, "search-input"
# 商品搜索按钮
product_search_btn = By.ID, "ai-topsearch"
# 第一个商品
product_search_after_product = By.XPATH, "/html/body/div[1]/div[1]/div[5]/div/div[4]/ul/li[1]"

"""商品购买配置相关元素"""
# 第一个套餐
product_config_package = By.XPATH, "/html/body/div[1]/div[1]/div[5]/div[2]/div[2]/div/div[2]/dl/dd/div[2]/div[3]/form/div[1]/div[1]/div[1]/ul/li"
# 第一个颜色
product_config_color = By.XPATH, "/html/body/div[1]/div[1]/div[5]/div[2]/div[2]/div/div[2]/dl/dd/div[2]/div[3]/form/div[1]/div[1]/div[2]/ul/li[2]/span"
# 第一个容量
product_config_volume = By.XPATH, "/html/body/div[1]/div[1]/div[5]/div[2]/div[2]/div/div[2]/dl/dd/div[2]/div[3]/form/div[1]/div[1]/div[3]/ul/li[3]/span"
# 数量输入框
product_config_number = By.CLASS_NAME, "operate-number-input"
# 加入购物车按钮
product_cart_btn = By.XPATH, "/html/body/div[1]/div[1]/div[5]/div[2]/div[2]/div/div[3]/div[2]/button[2]"
# 获得提示信息
product_config_message = By.CLASS_NAME, "am-text-success"
# 关闭弹窗按钮
product_close_popup = By.CLASS_NAME, "am-close-spin"

"""商品购物车相关元素"""
# 点击购物车链接
product_cart_link = By.CLASS_NAME, "top-nav-items-cart"


def get_cart_elements(user_id=1):
    with DatabaseProcess() as db:
        # 增加按钮
        add_xpath = '//*[@id="data-list-{user_cart_id}"]/td[3]/div/span[2]'
        product_add_btn = By.XPATH, db.format_xpath_with_cart_id(add_xpath, user_id=user_id)
        # 减少按钮
        reduce_xpath = '//*[@id="data-list-{user_cart_id}"]/td[3]/div/span[1]'
        product_reduce_btn = By.XPATH, db.format_xpath_with_cart_id(reduce_xpath, user_id=user_id)

        # 选中框
        select_box_xpath = '//*[@id="data-list-{user_cart_id}"]/td[1]/label/span'
        product_select_box = By.XPATH, db.format_xpath_with_cart_id(select_box_xpath, user_id=user_id)

        # 点击收货按钮
        receive_xpath = '//*[@id="data-list-{order_id}"]/td[30]/button'
        product_receive_btn = By.XPATH, db.format_xpath_with_order_id(receive_xpath)

        return {
            'add_btn': product_add_btn,
            'reduce_btn': product_reduce_btn,
            'select_box': product_select_box,
            'receive_btn': product_receive_btn
        }


# 点击结算按钮
product_pay_btn = By.CLASS_NAME, "separate-submit"

# 选择收货地址
product_receive_address = By.ID, "data-list-1"

# 选择支付方式
product_pay_type = By.XPATH, '//*[@id="buy-items-payment"]/div/ul/li[2]'

# 点击提交订单
product_submit_order = By.CLASS_NAME, "buy-submit"

# 点击我的订单
product_my_order = By.LINK_TEXT, "我的订单"

# 点击提示框确认按钮
product_confirm_btn = By.CSS_SELECTOR, '.am-modal-btn[data-am-modal-confirm]'
"""商品评价相关元素"""


def get_comment_elements():
    with DatabaseProcess() as db:
        # 点击评论
        comment_xpath = '//*[@id="data-list-{order_id}"]/td[30]/a[2]'
        product_comment = By.XPATH, db.format_xpath_with_order_id(comment_xpath)

        # 点击星级满意度
        rating_start_xpath = '//*[@id="data-list-{order_id}"]/td[3]/div[1]/ul/li[5]'
        product_rating_start = By.XPATH, db.format_xpath_with_order_id(rating_start_xpath)

        return {
            'comment': product_comment,
            'rating_start': product_rating_start
        }


# 输入评语
product_comment_content = By.NAME, "content[]"

# 选择本地中的一张图片
product_comment_file_iframe = By.ID, "edui3_iframe"

product_comment_file_submit = By.CLASS_NAME, "plug-file-upload-submit"

product_comment_image = By.CSS_SELECTOR, '#filePickerReady input[name="file"]'

product_comment_image_upload = By.CLASS_NAME, "uploadBtn"

product_comment_image_submit = By.XPATH, '//*[@id="edui7_body"]/div[2]'

# 点击匿名
product_anonymous_comment = By.CLASS_NAME, "switch-checkbox"

# 点击提交
product_submit_comment = By.CSS_SELECTOR, 'button[type="submit"].am-btn-sm'

"""商品售后相关元素"""


def get_aftersale_elements():
    with DatabaseProcess() as db:
        # 点击申请售后
        aftersale_xpath = '//*[@id="data-list-{order_id}"]/td[2]/div[3]/div/a'
        product_apply_aftersale = By.XPATH, db.format_xpath_with_order_id(aftersale_xpath)

        return {
            'aftersale': product_apply_aftersale
        }


# 选择售后类型
product_aftersale_type = By.XPATH, "/html/body/div[1]/div[1]/div[4]/div/div/div[2]/div[2]/div/div[2]"

# 点击退款原因下拉框
product_aftersale_foot = By.CLASS_NAME, "body-content-footer-container"
product_refund_reason_drop_down = By.CSS_SELECTOR, ".am-form-group .chosen-container"

# 选择退款原因
product_aftersale_refund_reason = By.CSS_SELECTOR, ".am-form-group .chosen-container li"

# 填写退款说明
product_aftersale_refund_desc = By.XPATH, "/html/body/div[1]/div[1]/div[4]/div/div/div[3]/div/form/div[4]/textarea"

# 上传凭证
product_aftersale_upload_proof = By.CLASS_NAME, "plug-file-upload-submit"

# 获取照片
product_aftersale_file_iframe = By.ID, "edui3_iframe"
product_aftersale_image_file = By.CSS_SELECTOR, '#filePickerReady input[name="file"]'

# 点击上传
product_aftersale_image_upload = By.CLASS_NAME, "uploadBtn"

# 点击确认
product_aftersale_image_submit = By.ID, "edui7_body"

# 点击售后提交按钮
product_aftersale_submit = By.CSS_SELECTOR, 'button[type="submit"].am-btn-sm'

# 点击立即退货
product_aftersale_return_goods = By.CLASS_NAME, "orderaftersale-delivery-submit"

# 输入快递名称
product_aftersale_express_name = By.NAME, "express_name"

# 输入快递号
product_aftersale_express_number = By.NAME, "express_number"

# 点击提交按钮
product_express_submit = By.CLASS_NAME, "btn-loading-example"

# 获取处理状态信息
product_aftersale_info = By.XPATH, "/html/body/div[1]/div[1]/div[4]/div/div/div/div/div[1]/div[2]/h1"

# 回到首页
product_return_index = By.LINK_TEXT, "首页"

"""后台登录相关元素"""
# 后台登录账号
back_login_accounts = By.NAME, "accounts"
# 后台登录密码
back_login_pwd = By.NAME, "pwd"
# 后台登录按钮
back_login_btn = By.CLASS_NAME, "am-btn-sub"

"""后台用户管理"""
# 用户管理链接
back_user_manage = By.CLASS_NAME, "menu-parent-items-126"
# 用户列表链接
back_user_list = By.XPATH, "/html/body/div[1]/div[1]/div/div/div[2]/div[2]/div/ul[4]/li[1]/a"
# 用户列表对应的iframe
back_user_list_iframe = By.XPATH, '//*[@id="ifcontent"]/div[3]/iframe'
# 输入用户名
back_input_username = By.NAME, "username"
# 输入昵称
back_input_nickname = By.NAME, "nickname"
# 输入手机号码
back_input_phone = By.NAME, "mobile"
# 输入电子邮箱
back_input_email = By.NAME, "email"
# 输入所在省
back_input_province = By.NAME, "province"
# 输入所在市
back_input_city = By.NAME, "city"
# 输入所在区
back_input_district = By.NAME, "county"
# 输入详细地址
back_input_address = By.NAME, "address"
# 输入有效积分
back_input_valid_points = By.NAME, "integral"
# 输入锁定积分
back_input_locked_points = By.NAME, "locking_integral"
# 输入生日
back_input_birthday = By.NAME, "birthday"
# 输入邀请人ID
back_input_inviter_id = By.NAME, "referrer"
# 输入登录密码
back_input_password = By.NAME, "pwd"
# 选择性别
back_select_gender = By.XPATH, "/html/body/div[2]/div/form/div[1]/div[14]/div/label[1]"
# 选择用户状态
back_select_user_status = By.XPATH, "/html/body/div[2]/div/form/div[1]/div[15]/div/label[1]"
# 提交添加按钮
back_btn_submit_add = By.XPATH, "/html/body/div[2]/div/form/div[2]/button"
# 添加按钮
back_add_btn = By.XPATH, "/html/body/div[2]/div/div[2]/form/div[2]/a"
# 删除选中按钮
back_delete_checked = By.CLASS_NAME, "form-table-operate-top-delete-submit"


def get_user_id():
    with DatabaseProcess() as db:
        # 删除用户按钮
        user_xpath = '//*[@id="data-list-{user_id}"]/td[23]/button[2]'
        back_delete_user = By.XPATH, db.format_xpath_with_user_id(user_xpath)
        # 编辑用户按钮
        update_xpath = '//*[@id="data-list-{user_id}"]/td[23]/a'
        back_update_user = By.XPATH, db.format_xpath_with_user_id(update_xpath)
        # 用户复选框
        user_check_xpath = '//*[@id="data-list-{user_id}"]/td[1]/div/label'
        back_user_check = By.XPATH, db.format_xpath_with_user_id(user_check_xpath)
        return {
            'back_delete_user': back_delete_user,
            'back_user_check': back_user_check,
            'back_update_user': back_update_user
        }


# 用户地址链接
back_user_address = By.XPATH, "/html/body/div[1]/div[1]/div/div/div[2]/div[2]/div/ul[4]/li[2]/a"
# 用户地址对应的iframe
back_user_address_iframe = By.XPATH, '//*[@id="ifcontent"]/div[4]/iframe'
# 输入用户id
back_input_user_id = By.NAME, "user_id"
# 输入姓名
back_input_name = By.NAME, "name"
# 输入别名
back_input_alias = By.NAME, "alias"
# 输入电话
back_input_tel = By.NAME, "tel"
# 点击省市区下拉框
back_click_area_dropdown = By.CLASS_NAME, "input-model"
# 点击所在省
back_click_province = By.XPATH, "/html/body/div[2]/div/form/div[5]/div/div[1]/div[2]/div[1]/div[1]/div/ul/li[4]"
# 点击所在市
back_click_city = By.XPATH, "/html/body/div[2]/div/form/div[5]/div/div[1]/div[2]/div[1]/div[2]/div/ul/li[2]/span"
# 点击所在区
back_click_district = By.XPATH, "/html/body/div[2]/div/form/div[5]/div/div[1]/div[2]/div[1]/div[3]/div/ul/li[3]/span"
# 输入详细地址
back_input_detailed_address = By.NAME, "address"
# 点击是否默认
back_click_is_default = By.CLASS_NAME, "switch-checkbox"
# 输入身份证姓名
back_input_id_card_name = By.NAME, "idcard_name"
# 输入身份证号码
back_input_id_card_number = By.NAME, "idcard_number"

back_input_id_card_image = By.CLASS_NAME, "user-address-idcard-images"
# 提交添加按钮
back_address_submit = By.XPATH, "/html/body/div[2]/div/form/div[11]/button"

back_address_update_submit = By.XPATH, "/html/body/div[2]/div/form/div[16]/button[1]"


def get_address_id():
    with DatabaseProcess() as db:
        # 删除用户地址按钮
        address_xpath = '//*[@id="data-list-{address_id}"]/td[16]/button[2]'
        back_delete_address = By.XPATH, db.format_xpath_with_address_id(address_xpath)
        # 编辑用户地址按钮
        address_update_xpath = '//*[@id="data-list-{address_id}"]/td[16]/a'
        back_update_address = By.XPATH, db.format_xpath_with_address_id(address_update_xpath)
        # 用户地址复选框
        address_check_xpath = '//*[@id="data-list-{address_id}"]/td[1]/div/label'
        back_address_check = By.XPATH, db.format_xpath_with_address_id(address_check_xpath)
        return {
            'back_delete_address': back_delete_address,
            'back_address_check': back_address_check,
            'back_update_address': back_update_address
        }


"""后台商品管理"""
# 一级标题：商品
back_first_level_product = By.XPATH, '//*[@id="admin-offcanvas"]/div/div[1]/div/div[2]/ul/li[6]/a'
# 二级标题：商品管理
back_second_level_product_management = By.XPATH, "/html/body/div[1]/div[1]/div/div/div[2]/div[2]/div/ul[5]/li[1]/a/p"
# 商品管理对应的iframe
back_product_management_iframe = By.XPATH, '//*[@id="ifcontent"]/div[3]/iframe'
# 商品名称
back_product_name = By.XPATH, '//*[@id="goods-nav-base"]/div[1]/div/input'
# 商品分类
back_product_category = By.XPATH, '//*[@id="goods-nav-base"]/div[2]/div/ul'
# 商品分类：手机
back_product_category_tel = By.XPATH, '//*[@id="goods-nav-base"]/div[2]/div/div/ul/li[3]'
# 商品描述
back_product_description = By.XPATH, '//*[@id="goods-nav-base"]/div[3]/input'
# 商品型号
back_product_model = By.XPATH, '//*[@id="goods-nav-base"]/div[4]/input'
# 品牌
back_product_brand = By.XPATH, '//*[@id="goods-nav-base"]/div[5]/div/a[1]/span'
# 商品-vivo
back_product_brand_vivo = By.XPATH, '//*[@id="goods-nav-base"]/div[5]/div/div/ul/li[21]'
# 生产地
back_product_origin = By.XPATH, '//*[@id="goods-nav-base"]/div[6]/div/a[1]/span'
# 生产地-山西
back_product_origin_shanxi = By.XPATH, '//*[@id="goods-nav-base"]/div[6]/div/div/ul/li[5]'
# 库存单位
back_product_stock_unit = By.XPATH, '//*[@id="goods-nav-base"]/div[7]/input'
# 购买赠送积分比例
back_product_point_ratio = By.XPATH, '//*[@id="goods-nav-base"]/div[8]/input'
# 排序权重
back_product_sort_weight = By.XPATH, '//*[@id="goods-nav-base"]/div[9]/input'
# 商品类型
back_product_type = By.XPATH, '//*[@id="goods-nav-base"]/div[10]/div/a/span'
# 商品类型-快递
back_product_type_express = By.XPATH, '//*[@id="goods-nav-base"]/div[10]/div/div/ul/li[2]'
# 封面图片按钮
back_product_cover_image_btn = By.XPATH, '//*[@id="goods-nav-base"]/div[11]/div/ul/li'
# 封面图片iframe
back_product_cover_image_iframe = By.ID, 'edui337_iframe'
# 封面图片
back_product_cover_image = By.CSS_SELECTOR, '#filePickerReady input[name="file"]'
# 封面图片上传
back_product_cover_image_upload = By.XPATH, '//*[@id="queueList"]/div[1]/div[3]/div[2]'
# 封面图片确认
back_product_cover_image_submit = By.ID, 'edui339_body'
# 商品规格
back_product_specs = By.XPATH, '/html/body/div[2]/div/form/div[1]/a[2]'
# 添加其他商品规格
back_product_add_other_specs = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[1]/span[1]'
# 商品规格添加一行
back_product_add_spec_row = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[2]/span'
# 新增规格的名称
back_product_add_other_specs_name = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[' \
                                              '1]/table/thead/tr[1]/th[1]/div/input '
# 新增规格的值
back_product_add_other_specs_number_row1 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[' \
                                                     '1]/table/tbody/tr[1]/td[1]/input '
back_product_add_other_specs_number_row2 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[' \
                                                     '1]/table/tbody/tr[2]/td[1]/input '
# 商品售价
back_product_selling_price_row1 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[' \
                                            '1]/table/tbody/tr[1]/td[2]/input '
back_product_selling_price_row2 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[' \
                                            '1]/table/tbody/tr[2]/td[2]/input '
# 商品原价
back_product_original_price_row1 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[' \
                                             '1]/table/tbody/tr[1]/td[3]/input '
back_product_original_price_row2 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[' \
                                             '1]/table/tbody/tr[2]/td[3]/input '
# 商品起购数
back_product_min_purchase_row1 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[' \
                                           '1]/td[4]/input '
back_product_min_purchase_row2 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[' \
                                           '2]/td[4]/input '
# 商品限购数
back_product_max_purchase_row1 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[' \
                                           '1]/td[5]/input '
back_product_max_purchase_row2 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[' \
                                           '2]/td[5]/input '
# 商品重量
back_product_weight_row1 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[1]/td[' \
                                     '6]/input '
back_product_weight_row2 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[2]/td[' \
                                     '6]/input '
# 商品体积
back_product_volume_row1 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[1]/td[' \
                                     '7]/input '
back_product_volume_row2 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[2]/td[' \
                                     '7]/input '
# 商品编码
back_product_code_row1 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[1]/td[' \
                                   '8]/input '
back_product_code_row2 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[2]/td[' \
                                   '8]/input '
# 商品条形码
back_product_barcode_row1 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[' \
                                      '1]/td[9]/input '
back_product_barcode_row2 = By.XPATH, '//*[@id="goods-nav-spec"]/div[2]/div/div[2]/div[2]/div[1]/table/tbody/tr[' \
                                      '2]/td[9]/input '
# 商品参数
back_product_parameters = By.XPATH, '/html/body/div[2]/div/form/div[1]/a[3]'
# 商品参数添加一行
back_product_add_param_row = By.XPATH, '//*[@id="goods-nav-parameters"]/div[1]/div[4]/span'
# 展示范围
back_product_display_scope = By.XPATH, '//*[@id="goods-nav-parameters"]/div[1]/div[3]/table/tbody/tr/td[1]/div/a'
# 展示范围-详情
back_product_display_scope_detail = By.XPATH, '//*[@id="goods-nav-parameters"]/div[1]/div[3]/table/tbody/tr/td[' \
                                              '1]/div/div/ul/li[2] '
# 参数名称
back_product_param_name = By.XPATH, '//*[@id="goods-nav-parameters"]/div[1]/div[3]/table/tbody/tr/td[2]/input'
# 参数值
back_product_param_value = By.XPATH, '//*[@id="goods-nav-parameters"]/div[1]/div[3]/table/tbody/tr/td[3]/input'
# 商品相册 / 商品视频
back_product_media = By.XPATH, '/html/body/div[2]/div/form/div[1]/a[4]'
# 商品相册
back_product_album_btn = By.XPATH, '//*[@id="goods-nav-photo"]/div/div'
# 商品视频
back_product_video_btn = By.XPATH, '//*[@id="goods-nav-video"]/div/ul/li'
# 手机详情
back_product_mobile_detail = By.XPATH, '/html/body/div[2]/div/form/div[1]/a[5]'
# 添加手机详情
back_product_add_mobile_detail = By.XPATH, '//*[@id="goods-nav-app"]/div[2]/span'
# 上传图片
back_product_tel_upload_image = By.XPATH, '//*[@id="goods-nav-app"]/div[2]/ul/li/div[1]/div[1]/div/ul/li'
# 文本内容
back_product_tel_text_content = By.XPATH, '//*[@id="goods-nav-app"]/div[2]/ul/li/div[1]/div[2]/textarea'
# 电脑详情
back_product_pc_detail = By.XPATH, '/html/body/div[2]/div/form/div[1]/a[6]'
# 电脑详情-image
back_product_pc_detail_image_frame = By.XPATH, '//*[@id="edui219_body"]/div/iframe'
back_product_pc_detail_image = By.CSS_SELECTOR, '.edui-default input[name="upfile"]'
# 电脑详情-iframe
back_product_pc_detail_iframe = By.ID, 'ueditor_1'
# 电脑详情-text
back_product_pc_detail_text = By.XPATH, '/html/body'
# 商品提交
back_product_submit = By.CSS_SELECTOR, 'button[type="submit"].am-btn-xs'
back_product_final = By.XPATH, '//*[@id="goods-nav-base"]/div[13]'
back_product_video_iframe = By.ID, 'edui342_iframe'
back_product_video_submit = By.ID, 'edui344_body'
back_product_tel_select = By.XPATH, '//*[@id="tabhead"]/span[2]'


def get_product_id():
    with DatabaseProcess() as db:
        # 商品管理-编辑商品按钮
        product_warehouse_xpath = '//*[@id="data-list-{product_id}"]/td[21]/a[1]'
        # 商品管理-选择商品按钮
        product_warehouse_select_xpath = '//*[@id="data-list-{product_id}"]/td[1]/div/label'
        back_update_product_btn = By.XPATH, db.format_xpath_with_product_id(
            product_warehouse_xpath)
        back_product_select = By.XPATH, db.format_xpath_with_product_id(
            product_warehouse_select_xpath)
        return {
            'back_update_product_btn': back_update_product_btn,
            'back_product_select': back_product_select
        }


# 一级标题：仓库
back_first_level_warehouse = By.XPATH, '//*[@id="admin-offcanvas"]/div/div[1]/div/div[2]/ul/li[10]/a'
# 二级标题：仓库商品管理
back_second_level_warehouse_management = By.XPATH, "/html/body/div[1]/div[1]/div/div/div[2]/div[2]/div/ul[9]/li[2]/a"
# 仓库商品管理对应的iframe
back_warehouse_management_iframe = By.XPATH, '//*[@id="ifcontent"]/div[5]/iframe'
# 仓库管理-添加按钮
back_warehouse_add_btn = By.CLASS_NAME, "add-goods-submit"
# 仓库管理-添加的商品
back_warehouse_add_product = By.XPATH, '//*[@id="warehouse-goods-popup"]/div/div[2]/form/div[2]/ul/li[1]/div/div/a/i'
back_warehouse_close = By.XPATH, '//*[@id="warehouse-goods-popup"]/div/div[1]/span[2]'


def get_product_warehouse_id():
    with DatabaseProcess() as db:
        # 仓库管理-添加的商品库存按钮
        product_warehouse_xpath = '//*[@id="data-list-{warehouse_id}"]/td[9]/button[2]'
        back_warehouse_add_product_warehouse_btn = By.XPATH, db.format_xpath_with_product_warehouse_id(
            product_warehouse_xpath)
        return {
            'back_warehouse_add_product_warehouse_btn': back_warehouse_add_product_warehouse_btn,
        }


# 仓库管理-库存iframe
back_warehouse_add_product_warehouse_frame = By.CSS_SELECTOR, '.am-popup-inner iframe'
# 仓库管理-添加的商品库存
back_warehouse_add_product_warehouse_row1 = By.XPATH, '/html/body/div[2]/div/form/table/tbody/tr[1]/td[2]/input[1]'
back_warehouse_add_product_warehouse_row2 = By.XPATH, '/html/body/div[2]/div/form/table/tbody/tr[2]/td[2]/input[1]'
# 仓库管理-添加的商品库存提交
back_warehouse_add_product_warehouse_submit = By.XPATH, '/html/body/div[2]/div/form/div/button[2]'

"""后台订单管理"""
# 一级标题：订单
back_first_level_order = By.XPATH, '//*[@id="admin-offcanvas"]/div/div[1]/div/div[2]/ul/li[7]/a'
# 二级标题：订单管理
back_second_level_order_management = By.XPATH, "/html/body/div[1]/div[1]/div/div/div[2]/div[2]/div/ul[6]/li[1]/a"
# 二级标题：订单售后
back_second_level_order_aftersale = By.XPATH, "/html/body/div[1]/div[1]/div/div/div[2]/div[2]/div/ul[6]/li[2]/a"
# 商品订单-订单售后iframe
back_order_aftersale_iframe = By.CSS_SELECTOR, '.iframe-item-key-364 iframe'
# 商品订单-订单管理iframe
back_order_manager_iframe = By.XPATH, '//*[@id="ifcontent"]/div[3]/iframe'
# 商品订单支付确认
back_order_pay_submit = By.XPATH, '//*[@id="order-pay-popup"]/div/div[2]/form/div[2]/button[2]'
# 商品订单-添加快递按钮
back_order_add_express_btn = By.XPATH, '/html/body/div[2]/form/div[1]/div/button'
# 商品订单-快递iframe
back_order_add_express_iframe = By.XPATH, '/html/body/div[101]/div/div[2]/iframe'
# 商品订单-快递方式
back_order_express_way_btn = By.XPATH, '//*[@id="popup-express-win"]/div/div[2]/form/div[1]/div/div/a'
# 商品订单-快递方式
back_order_express_way = By.XPATH, f'//*[@id="popup-express-win"]/div/div[2]/form/div[1]/div/div/div/ul/li[{random.randrange(2, 15, 1)}] '
# 商品订单-快递单号
back_order_express_number = By.XPATH, '//*[@id="popup-express-win"]/div/div[2]/form/div[2]/input'
# 商品订单-快递备注
back_order_express_note = By.XPATH, '//*[@id="popup-express-win"]/div/div[2]/form/div[3]/input'
back_order_express_submit = By.XPATH, '//*[@id="popup-express-win"]/div/div[2]/form/div[4]/button'
# 商品订单-快递提交
back_order_submit = By.XPATH, '/html/body/div[2]/form/div[2]/button[2]'


def get_order_id(order_id):
    order_pay_xpath = f'//*[@id="data-list-{order_id}"]/td[32]/button[2]'
    back_order_pay = By.XPATH, order_pay_xpath
    return back_order_pay


def get_order_aftersale_id(aftersale_id):
    # 商品订单售后-确认申请,审核
    order_xpath = f'//*[@id="data-list-{aftersale_id}"]/td[20]/button[2]'
    back_order_aftersale_confirm_or_audit = By.XPATH, order_xpath
    return back_order_aftersale_confirm_or_audit


# 商品订单售后-退款方式
back_order_express_refund_way = By.XPATH, '//*[@id="order-audit-popup"]/div/div[2]/form/div[1]/div/label[3]'

# 商品订单售后-退款方式确认
back_order_express_refund_way_submit = By.XPATH, '//*[@id="order-audit-popup"]/div/div[2]/form/div[2]/button[2]'
